package src.Packets;

import src.Util.Stream;
import src.Players.*;
import src.Main;
import src.Games.CastleWars;

public class Commands
{
    public Commands(Player p)
    {
        if(p == null || p.inStream == null)
        {
            return;
        }
        try
        {
            String command = p.inStream.readString();
            if(p.rights >= 0)
            {
                /*Commands for all users.*/
                if(command.startsWith("item"))
                {
                    String[] s = command.split(" ");
                    PlayerItems pi = new PlayerItems();
                    pi.addItem(p, Integer.parseInt(s[1]), Integer.parseInt(s[2]));
                    pi = null;
                }
                else if(command.startsWith("interface1"))
                {
                    String[] s = command.split(" ");
                    p.frame.showInterface(p, Integer.parseInt(s[1]));
                }
                else if(command.startsWith("interface2"))
                {
                    String[] s = command.split(" ");
                    p.frame.showInterface(p, Integer.parseInt(s[1]), Integer.parseInt(s[2]));
                }
                else if(command.startsWith("shop"))
                {
                    String[] s = command.split(" ");
                    p.viewShop(Integer.parseInt(s[1]));
                }
                else if(command.equals("bank"))
                {
                    p.frame.showInterface(p, 5292, 5063);
                    p.frame.resetItems(p, 5064);
                    p.frame.resetBank(p);
                }
                else if(command.startsWith("addxp"))
                {
                    String[] s = command.split(" ");
                    p.addSkillXP(Integer.parseInt(s[2]), Integer.parseInt(s[1]));
                }
                else if(command.startsWith("pnpc"))
                {
                    String[] s = command.split(" ");
                    //p.npcType = Integer.parseInt(s[1]);
                    //p.appearanceUpdateRequired = true;
                    //p.updateRequired = true;
                }
                else if(command.equals("coords"))
                {
                    p.frame.sendMessage(p, "absX = " + p.absX + ", absY = " + p.absY);
                }
                else if(command.equals("mask400"))
                {
                    p.mask400 = true;
                    p.updateRequired = true;
                }
                else if(command.equals("money"))
                {
                    PlayerItems pi = new PlayerItems();
                    pi.addItem(p, 995, 500000);
                    pi = null;
                }
		else if(command.equals("hweapon"))
		{
		    String[] s = command.split(" ");
		    PlayerChecks pc = new PlayerChecks(p);
		    if(pc.playerHasWeapon(p, Integer.parseInt(s[1]))) {
			p.frame.sendMessage(p, "+");
		    } else {
			p.frame.sendMessage(p, "-");
		    }
		}
		else if(command.equals("hitem"))
		{
		    String[] s = command.split(" ");
		    PlayerChecks pc = new PlayerChecks(p);
		    if(pc.playerHasItem(p, Integer.parseInt(s[1]))) {
			p.frame.sendMessage(p, "+");
		    } else {
			p.frame.sendMessage(p, "-");
		    }
		}
		else if(command.equals("hcape"))
		{
		    String[] s = command.split(" ");
		    PlayerChecks pc = new PlayerChecks(p);
		    if(pc.playerHasCape(p, Integer.parseInt(s[1]))) {
			p.frame.sendMessage(p, "+");
		    } else {
			p.frame.sendMessage(p, "-");
		    }
		}
		else if(command.equals("hlegs"))
		{
		    String[] s = command.split(" ");
		    PlayerChecks pc = new PlayerChecks(p);
		    if(pc.playerHasLegs(p, Integer.parseInt(s[1]))) {
			p.frame.sendMessage(p, "+");
		    } else {
			p.frame.sendMessage(p, "-");
		    }
		}
		else if(command.equals("hplate"))
		{
		    String[] s = command.split(" ");
		    PlayerChecks pc = new PlayerChecks(p);
		    if(pc.playerHasPlate(p, Integer.parseInt(s[1]))) {
			p.frame.sendMessage(p, "+");
		    } else {
			p.frame.sendMessage(p, "-");
		    }
		}
		else if(command.equals("hhelmet"))
		{
		    String[] s = command.split(" ");
		    PlayerChecks pc = new PlayerChecks(p);
		    if(pc.playerHasHelmet(p, Integer.parseInt(s[1]))) {
			p.frame.sendMessage(p, "+");
		    } else {
			p.frame.sendMessage(p, "-");
		    }
		}
		else if(command.equals("hgloves"))
		{
		    String[] s = command.split(" ");
		    PlayerChecks pc = new PlayerChecks(p);
		    if(pc.playerHasGloves(p, Integer.parseInt(s[1]))) {
			p.frame.sendMessage(p, "+");
		    } else {
			p.frame.sendMessage(p, "-");
		    }
		}
		else if(command.equals("hboots"))
		{
		    String[] s = command.split(" ");
		    PlayerChecks pc = new PlayerChecks(p);
		    if(pc.playerHasBoots(p, Integer.parseInt(s[1]))) {
			p.frame.sendMessage(p, "+");
		    } else {
			p.frame.sendMessage(p, "-");
		    }
		}
		else if(command.equals("hshield"))
		{
		    String[] s = command.split(" ");
		    PlayerChecks pc = new PlayerChecks(p);
		    if(pc.playerHasShield(p, Integer.parseInt(s[1]))) {
			p.frame.sendMessage(p, "+");
		    } else {
			p.frame.sendMessage(p, "-");
		    }
		}
		else if(command.equals("hring"))
		{
		    String[] s = command.split(" ");
		    PlayerChecks pc = new PlayerChecks(p);
		    if(pc.playerHasRing(p, Integer.parseInt(s[1]))) {
			p.frame.sendMessage(p, "+");
		    } else {
			p.frame.sendMessage(p, "-");
		    }
		}
		else if(command.equals("hnecklace"))
		{
		    String[] s = command.split(" ");
		    PlayerChecks pc = new PlayerChecks(p);
		    if(pc.playerHasNecklace(p, Integer.parseInt(s[1]))) {
			p.frame.sendMessage(p, "+");
		    } else {
			p.frame.sendMessage(p, "-");
		    }
		}
		else if(command.equals("harrows"))
		{
		    String[] s = command.split(" ");
		    PlayerChecks pc = new PlayerChecks(p);
		    if(pc.playerHasArrows(p, Integer.parseInt(s[1]))) {
			p.frame.sendMessage(p, "+");
		    } else {
			p.frame.sendMessage(p, "-");
		    }
		}
		else if(command.equals("teleport"))
		{
		    String[] s = command.split(" ");
		    p.teleportToPoint(Integer.parseInt(s[1]), Integer.parseInt(s[2]), Integer.parseInt(s[3]));
		}
		else if(command.equals("cwplayers"))
		{
		    CastleWars cw = new CastleWars();
		    cw.getPlayers();
		}
            }
        }
        catch (Exception e)
        {
            p.frame.sendMessage(p, e.getMessage());
            e.printStackTrace();
        }
    }
}